package zeebe.demo;

import io.zeebe.client.ZeebeClient;
import io.zeebe.client.api.response.DeploymentEvent;
import io.zeebe.client.api.worker.JobWorker;

public class DemoDeploy {
    public static void main(String[] args) {
        System.out.println("创建Zeebe的连接");
        ZeebeClient client = ZeebeClient.newClientBuilder()
                .brokerContactPoint("localhost:26500")
                .usePlaintext()
                .build();

        System.out.println("部署工作流");
        String bpmnPath = "bpmn/zeebeDemo.bpmn";
        DeploymentEvent deployment = client.newDeployCommand()
                .addResourceFromClasspath(bpmnPath)
                .send()
                .join();

        System.out.println("部署helloJobWorker");
        String helloType = "say-hello";
        HelloJobWorkerHandler helloHandler = new HelloJobWorkerHandler(client);
        JobWorker helloJobWorker = client.newWorker()
                .jobType(helloType)
                .handler(helloHandler)
                .open();

        System.out.println("部署worldJobWorker");
        String worldType = "say-world";
        WorldJobWorkerHandler worldHandler = new WorldJobWorkerHandler(client);
        JobWorker worldJobWorker = client.newWorker()
                .jobType(worldType)
                .handler(worldHandler)
                .open();
    }
}
